<template>
  <basic-container :btnFlag=true>
    <div class="card-border"
         style="padding-bottom: 28px;">
      <card-header :header-data="headerData"></card-header>
      <div class="step-group"
           style="padding: 70px 0 20px 20px;">
        <el-steps :active="state-1">
          <el-step :title="step.title"
                   :icon="step.icon"
                   :class="step.class"
                   v-for="(step,index) in stepList"
                   :key="index"></el-step>
        </el-steps>
      </div>
      <div style="float:right;margin-top:20px;"
           v-if="!(((category=='B' && planningRank == 'A') || category=='C') && state=='3')">
        <div style="width: 100px;display: inline-block;">
          <el-button type="success"
                     @click.stop="addOpinionCollection()">会审
          </el-button>
        </div>
        <div style="width: 100px;display: inline-block;margin-right: 10px;">
          <el-button type="primary"
                     @click.stop="opinionCollectionList()">查看会审
          </el-button>
        </div>
      </div>
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="titleView">
        <span class="form-label">标题:</span>
        <el-input style="width: 600px"
                  placeholder="请输入意见或理由"
                  v-model="reviewForm.title">
        </el-input>
      </div>
      <div class="form-group-padding"
           style="margin-top: -3px">
        <span class="form-label">{{approvedControl}}</span>
        <el-radio-group v-model="reviewForm.approved">
          <el-radio :label="1">同意</el-radio>
          <el-radio :label="0">不同意</el-radio>
        </el-radio-group>
      </div>
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="category!='A' && !opinionShowFlag && state!='4'">
        <span class="form-label">发布范围:</span>
        <el-select v-model="reviewForm.openScope"
                   placeholder="请选择"
                   style="width: 280px;">
          <el-option v-for="item in publishDIC"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value"></el-option>
        </el-select>
      </div>
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="opinionShowFlag">
        <span class="form-label">意见或理由:</span>
        <div style="width: 500px;display: inline-block;">
          <el-input type="textarea"
                    :rows="2"
                    placeholder="请输入意见或理由"
                    v-model="reviewForm.opinion">
          </el-input>
        </div>
      </div>
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="state == '2' && category != 'A' && !opinionShowFlag">
        <span class="form-label"
              style="float: left;font-weight: 600">会审意见:</span>
        <el-upload class="upload-demo"
                   ref="upload"
                   action="string"
                   :http-request="fileUploadRequest"
                   :on-preview="fileHandlePreview"
                   :on-remove="fileHandleRemove"
                   :auto-upload="true">
          <el-button slot="trigger"
                     size="small"
                     type="primary">点击上传
          </el-button>
        </el-upload>
      </div>
      <!--发布方式 政府审批阶段 专项规划 重点-->
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="state == '3' && ((category == 'C')||(category == 'B'&& planningRank == 'A')) && !opinionShowFlag">
        <span class="form-label">发布方式:</span>
        <div style="width: 500px;display: inline-block;">
          <el-select v-model="reviewForm.releaseWay"
                     style="width: 280px;">
            <el-option v-for="item in releaseWayDIC"
                       :key="item.value"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </div>
      </div>
      <!--征求意见 区域规划+专项规划（重点）发改审核阶段-->
      <div class="form-group-padding"
           style="margin-top: -3px"
           v-if="state == '2' && !opinionShowFlag">
        <span class="form-label"
              style="float: left;font-weight: 600">征求意见:</span>
        <el-upload class="upload-demo"
                   ref="upload"
                   action="string"
                   :http-request="opinionfileUploadRequest"
                   :on-preview="opinionfileHandlePreview"
                   :on-remove="opinionfileHandleRemove"
                   :auto-upload="true">
          <el-button slot="trigger"
                     size="small"
                     type="primary">点击上传
          </el-button>
        </el-upload>

      </div>
      <div style="text-align: center; margin-top: 40px;margin-bottom: 40px;">
        <el-button type="warning"
                   @click="transact()">确定
        </el-button>
        <el-button type="info"
                   @click.stop="goBack()">关闭
        </el-button>
      </div>
      <el-collapse v-model="activeNames"
                   style="margin-top:2rem;">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="card-header collapse-header">
              <div class="head-title collapse-title">{{reviewDetailControl}}</div>
            </div>
          </template>
          <div class="searchDetail">
            <examine-detail :id="reviewId"></examine-detail>
          </div>
        </el-collapse-item>
        <el-collapse-item name="2">
          <template slot="title">
            <div class="card-header collapse-header">
              <div class="head-title collapse-title">规划信息</div>
            </div>
          </template>
          <div class="searchDetail">
            <plan-detail :id="taskId"></plan-detail>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
  </basic-container>
</template>
<script>
  import {REVIEW_DIC} from '@/const/dict'
  import {
    cityConpress,
    cityGov,
    conpress,
    deptFirst,
    gov,
    provinceCongress,
    provinceGov,
    reviewRegDetail,
    expertOpinion
  } from "@/api/review";
  import getDetailData from "@/mixins/getDetailData";
  import {getfileinfopage} from "@/api/system";
  import getReviewDetail from "@/mixins/review/getReviewDetail";
  import {resultDetail} from "@/api/planning/result";
  import fileTypeMixin from "@/mixins/fileTypeMixin";
  import {stepMap, getStepList, stateUrlMap} from "@/views/review/const"
  import planDetail from "@/components/review/planDetail/planDetail"
  import examineDetail from "@/components/review/examineDetail/examineDetail"
  import {mapGetters} from "vuex";
  import {reviewDetail} from "@/api/review";
  import {getAchievementDetail} from "@/api/achievement";

  export default {
    name: "transact",
    mixins: [fileTypeMixin, getDetailData(), getReviewDetail()],
    computed: mapGetters(["deptInfo"]),
    data() {
      return {
        titleView: false,
        reviewForm: {
          approved: 1,// 审核意见、默认同意
          releaseWay: '0',
          joint: '0',
          openScope: '0',
          title: null,
        },
        // 专家评审意见表单
        peerReviewedForm: {},
        activeNames: ["1", "2"],
        detailData: [],
        // 发布方式字典
        publishDIC: REVIEW_DIC.publishDIC,
        releaseWayDIC: REVIEW_DIC.releaseWayDIC,
        headerData: {
          title: '审批办理'
        },
        state: '',
        category: '',
        planningRank: '',
        openScopeSource: '',
        stepList: [],
        stepMap: stepMap,
        // 审核意见和理由是否显示
        opinionShowFlag: false,
        // 规划文本（部分公开）是否显示
        txtHalfOpenShowFlag: false,
        // 专家评审弹框标志
        peerReviewedDialogVisible: false,
        // 最新专家评审弹框标志
        peerReviewedLastestDialogVisible: false,
        fileType: '会审意见',
        approvedControl: '审批结果',
        reviewDetailControl: '审批信息',
        orgNameTemp: null,
      };
    },
    created() {
      this.state = this.$route.params.state;
      this.taskId = this.$route.query.taskId;
      this.reviewId = this.$route.query.reviewId;
      this.getDetailData();
      this.getDetailData_review(this.reviewId);
      this.category = this.$route.query.category;
      this.planningRank = this.$route.query.planningRank;
      this.getListStep();
      this.putNameControl();
      this.putTitle();
    },
    components: {
      planDetail,
      examineDetail
    },
    watch: {
      'reviewForm.releaseWay'(val) {
        if (val == '0') {
          this.reviewForm.joint = '0'
        } else if (val == '1') {
          this.reviewForm.joint = '1'
        }
      },
      'reviewForm.approved'(val) {
        if (val == 0) {
          this.opinionShowFlag = true
        } else {
          this.opinionShowFlag = false
        }
      },
      'reviewForm.openScope'(val) {
        if (val == 1) {
          this.txtHalfOpenShowFlag = true;
          if (this.openScopeSource != 1) {
            this.reviewForm.approved = 0;
          }
        } else {
          this.txtHalfOpenShowFlag = false
        }
      }
    },
    methods: {
      putTitle() {
        if (this.$route.query.category == 'A' && this.$route.query.state == '3') {//发展规划政府审定阶段
          this.titleView = true;
          this.reviewForm.title = this.deptInfo.name + '关于要求对《' + this.$route.query.achievementTitle + '》审定的请示'
        } else if (this.$route.query.category == 'A' && this.$route.query.state == '4') {//发展规划政府人大审议阶段
          reviewDetail(this.$route.query.reviewId).then(async response => {
            this.reviewForm.title = await response.data.data.title;
          })
        } else if (this.$route.query.planningRank == 'B' && this.$route.query.category == 'B' && this.$route.query.state == '2') {//一般专项发改审批阶段
          reviewDetail(this.$route.query.reviewId).then(async response => {
            this.reviewForm.title = await response.data.data.title;
          })
        } else if (this.$route.query.planningRank == 'A' && this.$route.query.category != 'A' && this.$route.query.state == '2') {//重点专项发改初审阶段
          getAchievementDetail(this.$route.query.achievementId).then(async response => {
            this.orgNameTemp = await response.data.data.orgName;
            this.titleView = true;
            this.reviewForm.title = '发展改革委、' + this.orgNameTemp + '关于要求批复《' + this.$route.query.achievementTitle + '》的请示';
          })
        } else if (this.$route.query.planningRank == 'A' && this.$route.query.category != 'A' && this.$route.query.state == '3') {//重点专项政府审批阶段
          reviewDetail(this.$route.query.reviewId).then(async response => {
            this.reviewForm.title = await response.data.data.title;
          })
        } else if(this.$route.query.category == 'A' && this.$route.query.state == '2'){
          this.titleView = true;
          this.reviewForm.title = this.deptInfo.name + '关于要求对《' + this.$route.query.achievementTitle + '》审定的请示'
        }
      },
      goBack() {
        this.$router.go(-1);
      },
      // 获取规划详情信息
      getDetailData() {
        reviewRegDetail(this.taskId).then(response => {
          resultDetail(response.data.data.achievementId).then(response => {
            this.getresultDetail(response);
          })
        })
      },
      async getresultDetail(response) {
        if (response.data.code == '0') {
          var records = response.data.data;
          // 获取规划等级和规划类别为类判断【是否联合印发】的填写
          this.planningRank = records.planningRank;
          this.category = records.category;
          this.openScopeSource = records.openScope;
          if (records.fileId != "" && records.fileId != null) {
            this.multiplefiles = [];
            this.multiplefiles = await this.getfileinfopagetemp(records);
          }
          this.pmuc = records.pmuc;
          this.getresultDetailDate(records)
        }
      },
      getfileinfopagetemp(records) {
        return new Promise((resolve, reject) => {
          if (records.fileId != "" && records.fileId != null) {
            getfileinfopage(Object.assign({
              current: 1,
              size: 100,
              fileIds: records.fileId
            })).then(response => {
              var multiplefiles = response.data.data.records;
              resolve(multiplefiles);
            }).catch(
            )
          }
        })
      },
      // 办理
      transact() {
        if (stateUrlMap[this.state] && stateUrlMap[this.state].transact instanceof Function) {
          stateUrlMap[this.state].transact(this)
        }
      },
      // 查看会审
      opinionCollectionList(row, index) {
        // let src = `/opinionCollectionList/list/${this.$route.query.reviewId}`;
        // this.$router.push({
        //   path: src,
        //   query:{
        //     type:'5'
        //   }
        // })
        let src = `/collectionListReview/list/${this.$route.query.reviewId}`;
        this.$router.push({
          path: src,
          query: {
            type: '5',
            achievementTitle: this.$route.query.achievementTitle,
          }
        })
      },
      // 发起征集意见
      addOpinionCollection() {
        let src = `/opinionCollectionReview/add/${this.$route.query.reviewId}`;
        this.$router.push({
          path: src,
          query: {
            type: '5',
            achievementTitle: this.$route.query.achievementTitle,
          }
        })
      },
      // 成功提示
      sucNotify() {
        this.$notify({
          title: '成功',
          message: '办理成功',
          type: 'success',
          duration: 2000
        });
        this.$router.go(-1);
      },
      // 市级人大审议
      cityConpress() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          cityConpress(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 市级政府审议
      cityGov() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          cityGov(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 本级人大审议
      conpress() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          conpress(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 部门初审
      deptFirst() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.reviewForm.revisionProgress = this.getFileIds(this.fileTypeIds[this.fileType]);
          this.reviewForm.opinionAnnex = this.getFileIds(this.fileTypeIds['征求意见附件']);
          // this.reviewForm.txtHalfOpen = this.getFileId(this.fileTypeIds['规划文本(部分公开)'])
          deptFirst(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 本级政府审议
      gov() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          if (!this.reviewForm.releaseWay) {
            this.reviewForm.releaseWay = '0'
          }
          gov(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 省级人大审议
      provinceCongress() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          provinceCongress(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 省级政府审议
      provinceGov() {
        this.$confirm("确定办理么?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          provinceGov(this.taskId, this.reviewForm).then(response => {
            if (response.data.code == 0) {
              this.sucNotify()
            }
          })
        })
      },
      // 获取步骤
      getListStep() {
        this.stepList = getStepList(this.category, this.planningRank, this.stepMap)
      },
      opinionfileUploadRequest(params) {
        this.fileUploadRequestName(params, '征求意见附件')
      },
      opinionfileHandlePreview(file) {
        this.fileHandlePreviewName(file, '征求意见附件')
      },
      // 材料清单附件移除
      opinionfileHandleRemove(file) {
        this.fileHandleRemoveName(file, '征求意见附件')
      },
      putNameControl() {
        if (this.$route.params.state == '2') {
          if (this.$route.query.planningRank == 'B' && this.$route.query.category == 'B') {
            this.headerData.title = '审批办理';
            this.approvedControl = '审批结果';
            this.reviewDetailControl = '审批信息';
          } else {
            this.headerData.title = '审核办理';
            this.approvedControl = '审核结果';
            this.reviewDetailControl = '审核信息';
          }
        } else if (this.$route.params.state == '3') {
          if (this.$route.query.category == 'A') {
            this.headerData.title = '审核办理';
            this.approvedControl = '审核结果';
            this.reviewDetailControl = '审核信息';
          } else {
            this.headerData.title = '审批办理';
            this.approvedControl = '审批结果';
            this.reviewDetailControl = '审批信息';
          }
        } else if (this.$route.params.state == '4') {
          this.headerData.title = '审批办理';
          this.approvedControl = '审批结果';
          this.reviewDetailControl = '审批信息';
        }
      },


    }
  };
</script>

<style lang="scss" scoped>
</style>
